********************************************************************************
*Table A5; Column 1 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_blacks, clear

preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13 
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13 

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newbw2500 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a5_c1", replace
forvalues i=1/500 {
use $data/estimation_sample_blacks, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newbw2500 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_a5_c1, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/


********************************************************************************
*Table A5; Column 2 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
use $data/estimation_sample_blacks, clear

preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13 
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13 

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newpretermLT37 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a5_c2", replace
forvalues i=1/500 {
use $data/estimation_sample_blacks, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newpretermLT37 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_a5_c2, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/



********************************************************************************
*Table A5; Column 3 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
use $data/estimation_sample_whites, clear

preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13 
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13 

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newbw2500 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a5_c3", replace
forvalues i=1/500 {
use $data/estimation_sample_whites, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newbw2500 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_a5_c3, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/


********************************************************************************
*Table A5; Column 4 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
use $data/estimation_sample_whites, clear

preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13 
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13 

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newpretermLT37 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a5_c4", replace
forvalues i=1/500 {
use $data/estimation_sample_whites, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4



gen plus0d2=plus0*more_13
gen plus1d2=plus1*more_13
gen plus2d2=plus2*more_13
gen plus3d2=plus3*more_13
gen plus4d2=plus4*more_13

g bytimesdr= by*more_13
g bstatetimesdr=mom_birth_state*more_13
g agetimesdr=age_cat*more_13
g tbotimesdr =tbo*more_13
g maletimesdr= male*more_13
g yeartimesdr=more_13*year
g birth_monthdr=more_13*birth_month


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*more_13
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newpretermLT37 $treat_var  more_13  i.age_cat i.tbo i.male  i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr   i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_a5_c4, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/